import { useEffect } from 'react';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import {Toast} from 'antd-mobile'
import getPathAndQuery from '@/hooks/getPathAndQuery'
const useRequireAuth = () => {
  const { data: session, status } = useSession();
  const router = useRouter();
  const pathAndQuery = getPathAndQuery()
  useEffect(() => {
    if (status === 'unauthenticated') {
      Toast.show({ icon: 'fail', content: '会话过期' })
      setTimeout(() => {
        router.push(`/login?return_to=${pathAndQuery}`)
      }, 1500);
    }
  }, [status, router]);
};

export default useRequireAuth;